import request from '@/modules/index/utils/request';
import { downloadFile } from '@/utils/common';
import { Message } from 'element-ui';
import qs from 'qs';

const store = {
  actions: {
    // 分页查询我发布的任务
    async tagAdminCalibrationSearch (context, params) {
      const data = await request({
        url: '/calibration/search',
        method: 'post',
        data: params
      });
      return data;
    },
    // 分页查询我被分配的任务
    async tagAdminCalibrationSearchDetails (context, params) {
      const data = await request({
        url: '/calibration/search-details',
        method: 'post',
        data: params
      });
      return data;
    },
    // 新增任务
    async tagAdminCalibrationSave (context, params) {
      const data = await request({
        url: '/calibration/save',
        method: 'post',
        data: params
      });
      return data;
    },
    // 新增任务-创建标签
    async tagAdminClassifyIdBatchSave (context, params) {
      const data = await request({
        url: `/classify/${params.id}/batchSave`,
        method: 'post',
        data: params.data
      });
      return data;
    },
    // 新增任务-下载模板
    async tagAdminCalibrationDownloadExample (context, params) {
      const data = await request({
        url: '/calibration/downloadExample',
        method: 'post',
        params: params,
        responseType: 'blob'
      });
      if (!data.data) {
        Message.error("下载文件失败");
        return;
      }
      downloadFile(data);
    },
    // 新增任务-上传文件
    async tagAdminCalibrationUploadFile (context, params) {
      const data = await request({
        url: `/calibration/upload/${params.id}`,
        method: 'post',
        data: params.file,
        headers: {
          'Content-Type': 'multipart/form-data'
        }
      });
      return data;
    },
    // 下载数据
    async tagAdminCalibrationIdCreateCalibrationData (context, params) {
      const data = await request({
        url: `/calibration/${params.id}/createCalibrationData`,
        method: 'post',
        params: params,
        responseType: 'blob'
      });
      if (!data.data) {
        Message.error("下载文件失败");
        return;
      }
      downloadFile(data);
    },
    // 下载个人标定的数据
    async tagAdminCalibrationIdCreateCalibrationDetailsData (context, params) {
      const data = await request({
        url: `/calibration/${params.id}/createCalibrationDetailsData`,
        method: 'post',
        params: params,
        responseType: 'blob'
      });
      if (!data.data) {
        Message.error("下载文件失败");
        return;
      }
      downloadFile(data);
    },
    // 批量删除任务
    async tagAdminCalibrationBatchDelete (context, params) {
      const data = await request({
        url: '/calibration/batch',
        method: 'delete',
        params: params,
        paramsSerializer: params => {
          return qs.stringify(params, { indices: false })
        }
      });
      return data;
    },
    // 生成我的数据集
    async tagAdminCalibrationIdGenerateCalibrationData (context, params) {
      const data = await request({
        url: `/calibration/${params.calibrationId}/generateCalibrationData`,
        method: 'post',
        // params: params,
        data: params
      });
      return data;
    },
    // 查看数据标注信息详情
    async tagAdminCalibrationSearchDetailsByCalibrationId (context, params) {
      const data = await request({
        url: '/calibration/search-details-by-calibrationId',
        method: 'post',
        data: params
      });
      return data;
    },
    // ************************* 详情 *************************
    // 查询个人标定进度
    async tagAdminCalibrationSearchProgressByFinisher (context, params) {
      const data = await request({
        url: '/calibration/search-progress-by-finisher',
        method: 'post',
        // params: params,
        data: params
      });
      return data;
    },

    // ************************* 文本 *************************
    // 未标注文本列表
    async tagAdminCalibrationGetTxtNoDetails (context, params) {
      const data = await request({
        url: '/calibration/get-txt-no-details',
        method: 'post',
        data: params
      });
      return data;
    },
    // 已标注文本列表
    async tagAdminCalibrationGetTxtDetails (context, params) {
      const data = await request({
        url: '/calibration/get-txt-details',
        method: 'post',
        data: params
      });
      return data;
    },
    // 文本已配置的标签（含数量）
    async tagAdminCalibrationCountTxtHascalibrated (context, params) {
      const data = await request({
        url: '/calibration/count-txt-hascalibrated',
        method: 'post',
        // params: params,
        data: params
      });
      return data;
    },
    // 查询标签
    async tagAdminClassifySearch (context, params) {
      const data = await request({
        url: '/classify/search',
        method: 'get',
        params: params,
      });
      return data;
    },
    // 标注文本
    async tagAdminCalibrationSaveTxtDetails (context, params) {
      const data = await request({
        url: `/calibration/${params.calibrationId}/save-txt-details`,
        method: 'post',
        data: params.list
      });
      return data;
    },
    // ************************* 图片 *************************
    // 图片列表(completed: [0: 未标注, 1: 已标注])
    async tagAdminCalibrationGetImgCalibrate (context, params) {
      const data = await request({
        url: '/calibration/get-img-calibrate',
        method: 'post',
        data: params
      });
      return data;
    },
    // 标注图片
    async tagAdminCalibrationIdSaveImgCalibrate (context, params) {
      const data = await request({
        url: `/calibration/${params.calibrationId}/save-img-calibrate`,
        method: 'post',
        data: params.list
      });
      return data;
    },
    // 图片已配置的标签（含数量）
    async tagAdminCalibrationCountImgHascalibrated (context, params) {
      const data = await request({
        url: '/calibration/count-img-hascalibrated',
        method: 'post',
        params: params,
      });
      return data;
    },
    // ************************* 声音 *************************
    // 声音列表
    async tagAdminCalibrationGetVoiceCalibrate (context, params) {
      const data = await request({
        url: '/calibration/get-voice-calibrate',
        method: 'post',
        data: params
      });
      return data;
    },
    // 标注声音
    async tagAdminCalibrationIdSaveVoiceCalibrate (context, params) {
      const data = await request({
        url: `/calibration/${params.calibrationId}/save-voice-calibrate`,
        method: 'post',
        data: params.list
      });
      return data;
    },
    // 音频已配置的标签（含数量）
    async tagAdminCalibrationCountVoiceHascalibrated (context, params) {
      const data = await request({
        url: '/calibration/count-voice-hascalibrated',
        method: 'post',
        params: params,
      });
      return data;
    },
    // ************************* 物体检测 *************************
    // 标记单图片多标签
    async tagAdminCalibrationIdBatchSaveImgLabels (context, params) {
      const data = await request({
        url: `/calibration/${params.picId}/batch-save-img-detect-labels`,
        method: 'post',
        data: params.list
      });
      return data;
    },
    // 获取单个图片的标签
    async tagAdminCalibrationLoadOnePicLabels (context, params) {
      const data = await request({
        url: '/calibration/loadOnePicLabels',
        method: 'get',
        params: params,
      });
      return data;
    },
    // 获取单个任务下的标签列表
    async tagAdminCalibrationLoadImgDetectCalibrationAllLabels (context, params) {
      const data = await request({
        url: '/calibration/loadImgDetectCalibrationAllLabels',
        method: 'get',
        params: params,
      });
      return data;
    },
    // 单图片打单标签
    async tagAdminCalibrationIdSaveImgDetectLabels (context, params) {
      const data = await request({
        url: `/calibration/${params.picId}/save-img-detect-labels`,
        method: 'post',
        data: params
      });
      return data;
    },
    // 单图片删除单个标签
    async tagAdminCalibrationDeleteImgDetectLabel (context, params) {
      const data = await request({
        url: `/calibration/delete-img-detect-label`,
        method: 'post',
        data: params
      });
      return data;
    },
    // 获取物体列表
    async tagAdminCalibrationGetImgDetectCalibrate (context, params) {
      const data = await request({
        url: `/calibration/get-img-detect-calibrate`,
        method: 'post',
        data: params
      });
      return data;
    },
    //
  }
};

export default store;
